#include<ext.h>
#include<mcu.h>
#include<eeprom.h>
#include<intrins.h>

void EepromAction(uchar cmd, uchar addressHighByte, uchar addressLowByte) {
    IAP_CONTR = ENABLE_ISP;
    IAP_CMD = cmd;
    IAP_ADDRH = addressHighByte;
    IAP_ADDRL = addressLowByte;
    IAP_TRIG = 0x46;
    IAP_TRIG = 0xb9;
    _nop_();
    IAP_CONTR = DISABLE_ISP;
}

uchar EepromReadByte(uchar high, uchar low) {
    EepromAction(ISP_IAP_BYTE_READ, high, low);
    return IAP_DATA;
}

void EepromWriteByte(uchar iapData, uchar high, uchar low) {
    IAP_DATA = iapData;
    EepromAction(ISP_IAP_BYTE_WRITE, high, low);
}

void EepromInitSector(uchar high, uchar low) {
    EepromAction(ISP_IAP_SECTOR_ERASE, high, low);
}